package com.xyzwps.example.stream;

import java.util.ArrayList;
import java.util.List;

public class Demo {

    public static void main(String[] args) {
        var s = new CollectionStream<>(List.of(2, 3, 4, 5, 6));
        var toList = new ReduceCollector<Integer, List<Integer>>(new ArrayList<>(), (i, list) -> {
            list.add(i);
            return list;
        });

        System.out.println(s
                .map(i -> {
                    int r = i * 2;
                    System.out.printf("1) map %d to %d \n", i, r);
                    return r;
                })
                .flatMap(i -> {
                    int t1 = i, t2 = i + 2;
                    System.out.printf("  2) flat map %d to %d, %d \n", i, t1, t2);
                    return new JustStream<>(t1, t2);
                })
                .filter(i -> {
                    boolean r = i > 6;
                    System.out.printf("    3) filter %d and %s it \n", i, r ? "keep" : "DROP");
                    return r;
                })
                .unique()
                .collect(toList));

    }
}

